package com.woniuxy.joylifeshop.service.serviceImpl;

import com.woniuxy.common.entity.ShopMerchantCurrentAccount;
import com.woniuxy.common.entity.ShopMerchantCurrentAccountExample;
import com.woniuxy.common.mapper.ShopMerchantCurrentAccountMapper;
import com.woniuxy.joylifeshop.exception.MerchantCurrentAccountException;
import com.woniuxy.joylifeshop.service.MerchantCurrentAccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MerchantCurrentAccountServiceImpl implements MerchantCurrentAccountService {

    @Autowired
    ShopMerchantCurrentAccountMapper shopMerchantCurrentAccountMapper;
    /**
    * @Author SooYoo
    * @Description 通过条件查询来找到流水对象
    * @Param 
    * @Return 
    **/
    @Override
    public List<ShopMerchantCurrentAccount> readCurrentObjectByCondition(ShopMerchantCurrentAccount shopMerchantCurrentAccount) {

        try {
            ShopMerchantCurrentAccountExample shopMerchantCurrentAccountExample = new ShopMerchantCurrentAccountExample();
            ShopMerchantCurrentAccountExample.Criteria criteria = shopMerchantCurrentAccountExample.createCriteria();
            criteria.andMerchantIdEqualTo(shopMerchantCurrentAccount.getMerchantId());

            if (shopMerchantCurrentAccount.getCurrentId()!=null && !shopMerchantCurrentAccount.getCurrentId().equals("")){
                criteria.andCurrentIdEqualTo(shopMerchantCurrentAccount.getCurrentId());
            }

            if (shopMerchantCurrentAccount.getCurrentType()!=null && !shopMerchantCurrentAccount.getCurrentType().equals("")){
                criteria.andCurrentTypeEqualTo(shopMerchantCurrentAccount.getCurrentType());
            }

            List<ShopMerchantCurrentAccount> shopMerchantCurrentAccounts = shopMerchantCurrentAccountMapper.selectByExample(shopMerchantCurrentAccountExample);
            System.out.println(shopMerchantCurrentAccounts);
            return shopMerchantCurrentAccounts;
        } catch (Exception e) {
            e.printStackTrace();
            throw new MerchantCurrentAccountException();
        }

    }

    /**
    * @Author SooYoo
    * @Description 生成一个商家流水对象
    * @Param 
    * @Return 
    **/
    @Override
    public void creatMerchantCurrentAccountObject(ShopMerchantCurrentAccount shopMerchantCurrentAccount) {

        shopMerchantCurrentAccountMapper.insert(shopMerchantCurrentAccount);


    }
}
